package com.lx.algorithm.heap;

import java.util.List;

/**
 * Description:
 * Copyright:   Copyright (c)2019
 * Company:     zefu
 *
 * @author: 张李鑫
 * @version: 1.0
 * Create at:   2021-09-12 12:25:33
 * <p>
 * Modification History:
 * Date         Author      Version     Description
 * ------------------------------------------------------------------
 * 2021-09-12     张李鑫                     1.0         1.0 Version
 */
public class HeapTest {

    public static void main(String[] args) {
        HeapGreater<Integer> integerHeapGreater = new HeapGreater<>((o1, o2) -> o2 - o1);
        MyHeap<Integer> integerMyHeap = new MyHeap<>((o1, o2) -> o2 - o1);

    }

    public static int[] generateRandomArray(int maxSize, int maxValue) {
        HeapGreater<Integer> integerHeapGreater = new HeapGreater<>((o1, o2) -> o2 - o1);
        MyHeap<Integer> integerMyHeap = new MyHeap<>((o1, o2) -> o2 - o1);
        int[] arr = new int[(int) ((maxSize + 1) * Math.random())];
        for (int i1 = 0; i1 < 100; i1++) {
            for (int i = 0; i < arr.length; i++) {
                int value = (int) ((maxValue + 1) * Math.random()) - (int) (maxValue * Math.random());
                integerHeapGreater.push(value);
                integerMyHeap.push(value);
            }
            List<Integer> allElements = integerHeapGreater.getAllElements();
            List<Integer> allElements1 = integerMyHeap.getAllElements();
            if (!isEqual(allElements,allElements1)){
                System.out.println("error");
            }
        }


        return arr;
    }


    public static boolean isEqual(List arr1, List arr2) {
        if ((arr1 == null && arr2 != null) || (arr1 != null && arr2 == null)) {
            return false;
        }
        if (arr1 == null && arr2 == null) {
            return true;
        }
        if (arr1.size() != arr2.size()) {
            return false;
        }
        for (int i = 0; i < arr1.size(); i++) {
            if (arr1.get(i) != arr2.get(i)) {
                return false;
            }
        }
        return true;
    }
}